package com.woniu.sharepark.platformsystem.controller;

import com.woniu.sharepark.common.JsonResult;
import com.woniu.sharepark.platformsystem.log.annonation.BackgroundLogAnnotation;
import com.woniu.sharepark.platformsystem.log.util.CircleResult;
import com.woniu.sharepark.platformsystem.pojo.Scale;
import com.woniu.sharepark.platformsystem.service.ScaleService;
import com.woniu.sharepark.vo.LayuiDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zy
 * @date 2019/6/5 19:27
 */
@RequestMapping("/scale")
@Controller
public class ScaleController {

    @Autowired
    private ScaleService scaleService;




    /**
     * 重新配置比例
     * @param scale
     * @return 返回受影响的行数
     */
    @RequestMapping("/update")
    @ResponseBody
    @BackgroundLogAnnotation(operate = "配置抽成比例")
    public JsonResult update(Scale scale){
        scale.setsId(1);

        try {
            Scale scaleResult = scaleService.updateScale(scale);
            return JsonResult.ok("配置成功");
        } catch (Exception ex) {
            ex.printStackTrace();
            return JsonResult.error("配置失败");
        }
    }

    /**
     * 以饼图形式展示抽成比例
     * @return
     */
    @RequestMapping("/circle")
    @ResponseBody
    public CircleResult scaleCircle(){
        Scale scale = scaleService.findScale();
        List mapValue = new ArrayList();
        mapValue.add(scale.getsCommunity());
        mapValue.add(scale.getsRent());
        mapValue.add(scale.getsSystem());

        List mapName = new ArrayList();
        mapName.add("物业方");
        mapName.add("出租方");
        mapName.add("平台方");

        return new CircleResult(mapValue,mapName);

    }

}
